package com.train.common.utils.resource;

import com.train.common.utils.jwt.JwtUtils;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class ResourceUtils {

    /**
     * 读取resources下的指定文件
     * @param fileName
     * @return
     */
    public static String readKey(String fileName) {
        ClassLoader classLoader = JwtUtils.class.getClassLoader();
        InputStream inputStream = classLoader.getResourceAsStream(fileName);
        if (inputStream == null) {
            throw new RuntimeException("密钥文件未找到: " + fileName);
        }
        try (Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8)) {
            return scanner.useDelimiter("\\A").next();
        }
    }
}
